import Vue from "vue";
import VueRouter from "vue-router";
import store from "@/store";
import { message } from "ant-design-vue";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    component: () => import("@/views/index.vue"),
  },
  {
    path: "/login",
    name: "Login",
    component: () => import("@/views/login.vue"),
  },
  {
    path: "/403",
    name: "Error403",
    component: () => import("@/views/403.vue"),
  },
];

const router = new VueRouter({
  //   mode: 'history',
  base: process.env.BASE_URL,
  routes,
});

router.beforeEach(async (_to, _from, next) => {
  store.commit("CLAER_CANCEL"); // 取消请求
  const title = _to.meta.title || "vue";
  document.title = title;
  // 判断登录和页面权限
  // let power = store.state.power;
  // let routerToken = _to.query.session_token;
  // if (routerToken) {
  //   store.commit("SET_TOKEN", routerToken);
  // }
  // let token = store.state.token || routerToken;
  // if (!token && _to.path !== "/login") {
  //   next("/login");
  // } else {
  //   if (_to.meta.power && power.indexOf(_to.meta.power) == -1) {
  //     message.error("暂无权限访问该页面");
  //     next({
  //       path: "/admin",
  //       replace: true,
  //     });
  //   } else {
      next();
  //   }
  // }
});

export default router;
